﻿$(function () {
    $("#dialog-form").dialog({
        autoOpen: false,
        height: 400,
        width: 500,
        modal: true,
        buttons: {
            "Print": function () {
                var bValid = true;
                printpage("divIngredientPrintDepart");
                //                $("#divIngredientPrintDepart").print();  
                if (bValid) {
                    $(this).dialog("close");
                }
            },
            Cancel: function () {
                $("#dialog-form").css('display', 'none');
                $(this).dialog("close");
            }
        }
    });
    $("#img_print")
    .button()
    .click(function () {
        $("#dialog-form").css('display', 'inherit');
        $("#dialog-form").dialog("open");
    });


    $("#dialog-sendemail").dialog({
        autoOpen: false,
        height: 400,
        width: 500,
        modal: true,
        buttons: {
            "Send": function () {
                var bValid = true;
                
                printpage("divIngredientSendDepart");
                //                $("#divIngredientPrintDepart").print();  
                if (bValid) {
                    $(this).dialog("close");
                }
            },
            Cancel: function () {
                $("#dialog-sendemail").css('display', 'none');
                $(this).dialog("close");
            }
        }
    });
    $("#img_send")
    .button()
    .click(function () {
        $("#dialog-sendemail").css('display', 'inherit');
        $("#dialog-sendemail").dialog("open");
    });
});



function printpage(print) {
    var headstr = "<html><head><title></title></head><body>";
    var footstr = "</body>";
    var newstr = document.all.item(print).innerHTML;
    var oldstr = document.body.innerHTML;
    document.body.innerHTML = headstr + newstr + footstr;
    window.print();
    var url = $(location).attr('href');
    self.location = url;
}